// 页面路径：store/index.js 
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex); //vue的插件机制

//Vuex.Store 构造器选项
const store = new Vuex.Store({
	state: { //存放状态
		tabbar: uni.getStorageSync('tabbar') || [],
		tabbarIndex: uni.getStorageSync('tabbarIndex') || 0,
		robot: uni.getStorageSync('robot') || {},
		modelList: uni.getStorageSync('modelList') || [],
		appList: uni.getStorageSync('appList') || [],
		theme: uni.getStorageSync('appTheme') || 'light',
		model: uni.getStorageSync('model') || {},
		temTentList:uni.getStorageSync('temTentList') || [],
		contNameTen:uni.getStorageSync('contNameTen') || {},
		//websocket
		role: '',
		showDesign: '',
		notifyCount: 0,
		openMusic: ''
	},
	mutations: {
		//内容模板 做拼接
		setContName(state, data) {
			state.contNameTen = data
			uni.setStorageSync('contNameTen', data)
		},
		//选中应用里面的所有、的数据
		setTentList(state, data) {
			state.temTentList = data
			uni.setStorageSync('temTentList', data)
		},
		setTheme(state, data) {
			state.theme = data
			uni.setStorageSync('appTheme', data)
		},
		setTabbar(state, data) {
			state.tabbar = data
			uni.setStorageSync('tabbar', data)
		},
		setTabbarIndex(state, data) {
			state.tabbarIndex = data
			uni.setStorageSync('tabbarIndex', data)
		},
		setRobot(state, data) {
			state.robot = data
			uni.setStorageSync('robot', data)
		},
		setModelList(state, data) {
			state.modelList = data
			uni.setStorageSync('modelList', data)
		},
		setAppList(state, data) {
			state.appList = data
			uni.setStorageSync('appList', data)
		},

		setModel(state, data) {
			state.model = data
			uni.setStorageSync('model', data)
		},

		//websocket模块
		changeUp(state, data) {
			state.role = data.role
			state.showDesign = data.design
			state.notifyCount = data.amount
			state.openMusic = data.open_music
		},
	},
	getters: {
		//websocket模块
		showDesign(state) {
			return state.showDesign
		},
		notifyCount(state) {
			return state.notifyCount
		},
		openMusic(state) {
			return state.openMusic
		}
	},
	actions: {
		//websocket模块
		changeUp(context, data) {
			context.commit('changeUp', data)
		}
	}
})
export default store